<?php
require_once './_classes/upload/class.upload.php';
class UploadFile{
    var $thumuc = "galery"; // thu muc luu file
    var $tenInputFile = array(); // ten input upload
    // upload nhieu file
    function doMulti($thumuc,$tenInputFile){
        $files = array();
        foreach ($tenInputFile as $k => $l) {
            foreach ($l as $i => $v) {
                if (!array_key_exists($i, $files))
                    $files[$i] = array();
                    $files[$i][$k] = $v;
            }
        }    
        foreach ($files as $file) {
            $handle = new upload($file,"vn_VN");
            if ($handle->uploaded) {
                $handle->file_new_name_body = convertText($handle->file_src_name_body);
                $handle->file_name_body_pre = 'manhlong_vn_';
                $handle->Process("_uploads/".$thumuc);
                if ($handle->processed) {
                    return "_uploads/".$thumuc."/".$handle->file_dst_name;
                } else {
                    echo '<fieldset>';
                    echo '  <legend>file not uploaded to the wanted location</legend>';
                    echo '  Error: ' . $handle->error . '';
                    echo '</fieldset>';
                }
            $handle->Clean();
            } else {
                echo '<fieldset>';
                echo '  <legend>file not uploaded on the server</legend>';
                echo '  Error: ' . $handle->error . '';
                echo '</fieldset>';
            }
        }
    }
    // upload 1 file
    function doSinple($thumuc,$tenInputFile){
        $handle = new upload($tenInputFile,"vn_VN");
        if ($handle->uploaded) {
        $handle->file_name_body_pre = 'manhlong_vn_';
        // yes, the file is on the server
        // now, we start the upload 'process'. That is, to copy the uploaded file
        // from its temporary location to the wanted location
        // It could be something like $handle->Process('/home/www/my_uploads/');
        $handle->Process("_uploads/".$thumuc);

        // we check if everything went OK
        if ($handle->processed) {
            // everything was fine !
           return "_uploads/".$thumuc."/".$handle->file_dst_name;
        } else {
            // one error occured
            echo '<fieldset>';
            echo '  <legend>file not uploaded to the wanted location</legend>';
            echo '  Error: ' . $handle->error . '';
            echo '</fieldset>';
        }
        // we delete the temporary files
        $handle-> Clean();
        } else {
            // if we're here, the upload file failed for some reasons
            // i.e. the server didn't receive the file
            echo '<fieldset>';
            echo '  <legend>file not uploaded on the server</legend>';
            echo '  Error: ' . $handle->error . '';
            echo '</fieldset>';
        }

    }

}
?>